package com.zzh.tools.sp;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;


import com.zzh.tools.ToolsConfig;

import java.util.HashSet;
import java.util.Set;

public class ToolSpUtils {

    private ToolSpUtils(){}

    private static class ToolSpUtilsHorder_PRIVATE{
        static SharedPreferences sSharedPreferences = ToolsConfig.mContext.getSharedPreferences(ToolsConfig.mSPName, Context.MODE_PRIVATE);
    }

    private static class ToolSpUtilsHorder_APPEND{
        static SharedPreferences sSharedPreferences = ToolsConfig.mContext.getSharedPreferences(ToolsConfig.mSPName, Context.MODE_APPEND);
    }


    //拿到标志位
    public static boolean getMark(String markName) {
        return ToolSpUtilsHorder_PRIVATE.sSharedPreferences.getBoolean(markName, false);
    }
    //改变标志位

    public static void setMark(String markName, boolean mark) {
        ToolSpUtilsHorder_APPEND.sSharedPreferences.edit().putBoolean(markName, mark).commit();
    }

    //拿到字符窜
    public static String getString(String key) {
        return ToolSpUtilsHorder_PRIVATE.sSharedPreferences.getString(key, "");
    }
    //改变自负攒

    public static void setString(String key, String value) {
        if (TextUtils.isEmpty(value)) {
            value = "";
        }
        ToolSpUtilsHorder_APPEND.sSharedPreferences.edit().putString(key, value).commit();
    }

    //拿到 int
    public static int getInt(String key) {
        return ToolSpUtilsHorder_PRIVATE.sSharedPreferences.getInt(key, 0);
    }

    //改变int 值
    public static void setInt(String key, int value) {
        ToolSpUtilsHorder_APPEND.sSharedPreferences.edit().putInt(key, value).commit();
    }

    //拿到 long
    public static long getLong(String key, Long dValue) {
        return ToolSpUtilsHorder_PRIVATE.sSharedPreferences.getLong(key, dValue);
    }

    //改变 long 值
    public static void setLong(String key, Long value) {
        ToolSpUtilsHorder_APPEND.sSharedPreferences.edit().putLong(key, value).commit();
    }


    public static void removeString(String key) {
        ToolSpUtilsHorder_PRIVATE.sSharedPreferences.edit().remove(key).commit();
    }

    public static void setStringSet(String key, HashSet value) {
        if (value == null && value.isEmpty()) return;
        ToolSpUtilsHorder_APPEND.sSharedPreferences.edit().putStringSet(key, value).commit();
    }

    //拿到 int
    public static Set getStringSet(String key) {
        return ToolSpUtilsHorder_APPEND.sSharedPreferences.getStringSet(key, null);
    }




}
